<?php
/**
 * Created by PhpStorm.
 * User: XD
 * Date: 2017/9/8
 * Time: 12:59
 */
//https://www.ibm.com/developerworks/cn/opensource/os-php-shared-memory/



function test(){
    $systemid = 864;
    $mode = "c";
    $permissions = 0755;
    $size = 1024;
    $shmid = shmop_open($systemid, $mode, $permissions, $size);
    return $shmid;
}

function test2(){
    $systemid = 865;
    $mode = "c";
    $permissions = 0755;
    $size = 1024;
    $shmid = shmop_open($systemid, $mode, $permissions, $size);
    return $shmid;
}

//些数据
//shmop_write($shmid, "Hello World!", 0);
//echo shmop_read($shmid, 0, 11);
//$size = shmop_size($shmid);  //1024


function close($shmid){
    shmop_delete($shmid);
shmop_close($shmid);
}

function run(){
    $shmid = test();
    $i=0;
    while (1){
        sleep(2);
        shmop_write($shmid, "Hello ".$i."World!", $i);
        $i = $i+13;
        if($i >= 1000){
            close($shmid);
            break;
        }
    }
}

run();